<?php
class c_public_function extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->model('m_public_function');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case "setdiv" :
				$this->_setdiv();
				break;
			case "project" :
				$this->_project();
				break;
			case "project2" :
				$this->_project2();
				break;
			case "divbyuser" :
				$this->_divbyuser();
				break;
			case "checklistbyflowdet" :
				$this->_checklistbyflowdet();
				break;
			case "flowdetfortable" :
				$this->_flowdetfortable();
				break;
			case "projectcodebyid" : 
				$this->_projectcodebyid();
				break;
            case "getnodocumen" : 
				$this->_getnodocumen();
				break;
			default : 
				redirect(base_url());
		}
	}
	
	function _setdiv(){
		$_SESSION[SESSION_DIV] = secure_post("div_id");
		echo $_SESSION[SESSION_DIV];
	}
	
	function _project(){
		echo json_encode($this->m_public_function->_project());
	}
    
	function _project2(){
		echo json_encode($this->m_public_function->_project2());
	}
	
	function _divbyuser(){
		$user_id = $_SESSION[SESSION_USERID];
		echo json_encode($this->m_public_function->_divbyuser($user_id));
	}
	
	function _checklistbyflowdet(){
		$flowdet_id = secure_post("flowdet_id");
		$last = secure_post("last");
		$document_id = secure_post("document_id");
		$is_last = ($last == @$_SESSION[SESSION_DIV]);
		echo json_encode($this->m_public_function->_checklistbyflowdet($flowdet_id, $document_id, $is_last,$last));
	}
	
	function _flowdetfortable(){
		$flow_id = secure_post("flow_id");
		echo json_encode($this->m_public_function->_flowdetfortable($flow_id));
	}
	
	function _projectcodebyid(){
		$project_id = secure_post("project_id");
		echo $this->m_public_function->projectcodebyid($project_id);
	}
    
    function _getnodocumen(){
		$project_id = secure_post("project_id");
		$flow_id = secure_post("flow_id");
		$data["project_code"] = $this->m_public_function->projectcodebyid($project_id);
		$data["seq"] = $this->m_public_function->_getdocumentno($flow_id, $project_id);
        echo json_encode($data);
    }
	
}